import { AxiosInstance, AxiosRequestConfig, AxiosResponse } from 'axios'
import request from './request'
import response from './response'

export const interceptor = {
  request,
  response
}

export const registerInterceptor = (instance: AxiosInstance) => {
  if (!instance) return

  for (const key in request) {
    instance.interceptors.request.use((config: AxiosRequestConfig) => request[key](config))
  }

  // 设置响应拦截器
  for (const key in response) {
    instance.interceptors.response.use((result: AxiosResponse) => response[key](result))
  }

  return instance
}
